package com.baizhi.action;

import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class AsynchronousCheckUsernameAction {
    private String username;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String execute() throws IOException, InterruptedException {
        System.out.println("username = " + username);
       // Thread.sleep(5000);
        HttpServletResponse resp = ServletActionContext.getResponse();
        resp.setCharacterEncoding("utf-8");
        PrintWriter pw = resp.getWriter();
        if("xushy".equals(username)){
            pw.print("用户名已存在,不可使用");
        }else{
            pw.print("用户名可以使用");
        }
        pw.flush();

        //不再跳转,return null
        return null;
    }
}
